﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using SuperX.SuperSocket.Socket.Transfer.Client.UpLoad;

namespace SuperX.SuperSocket.Socket.Transfer.Client
{
    internal class TransferEngine : ITransferEngine
    {
        private FileUploadingEvents _FileUploadingEvents;

        public IFileUploadingEvents FileUploadingEvents
        { get { return _FileUploadingEvents; } }

        private UpLoadClientEngine upLoadEngine;

        public TransferEngine()
        {
            _FileUploadingEvents = new FileUploadingEvents();
            _FileUploadingEvents.FileExist += (e) =>
            {
                return true;
            };
        }

        public void StartUpLoad(string ip, int port, string fileName, string saveName, ref string fileProjectId)
        {
            EndPoint endpoint = new IPEndPoint(IPAddress.Parse(ip), port);
            upLoadEngine = new UpLoadClientEngine(_FileUploadingEvents);
            upLoadEngine.Init(endpoint, fileName, saveName);
            upLoadEngine.StartUpLoad(ref fileProjectId);
        }

        public void StopUpLoad()
        {
            upLoadEngine.StopUpLoad();
        }

        public void Dispose()
        {
            upLoadEngine?.Dispose();
        }
    }
}